import axios from './index'

const preUrl = ''


// 获取公告列表
const getAnnounces = {
  p: [`get,/game/noticed/*`],
  r: params => {
    axios.defaults.headers['permission'] = `get,/game/noticed/*`
    return axios.get(`${preUrl}/game/noticed/${Cookie.get('areaCode')}`, {
      params
    })
  }
}

// 新增公告
const addAnnounce = {
  p: [`post,/game/noticed/*`],
  r: params => {
    axios.defaults.headers.permission = `post,/game/noticed/*`
    return axios.post(`${preUrl}/game/noticed/${Cookie.get('areaCode')}`, params)
  }
}

// 开启/关闭公告
const toggleAnnounce = {
  p: [`put,/game/noticed/*/valid`],
  r: params => {
    axios.defaults.headers.permission = `put,/game/noticed/*/valid`
    return axios.put(`${preUrl}/game/noticed/${Cookie.get('areaCode')}/valid`, params)
  }
}

// 编辑公告
const editAnnounce = {
  p: [`put,/game/noticed/*`],
  r: params => {
    axios.defaults.headers.permission = `put,/game/noticed/*`
    return axios.put(`${preUrl}/game/noticed/${Cookie.get('areaCode')}`, params)
  }
}

// 删除公告
const deleteAnnounce = {
  p: [`delete,/game/noticed/*/*`],
  r: params => {
    axios.defaults.headers.permission = `delete,/game/noticed/*/*`
    return axios.delete(`${preUrl}/game/noticed/${Cookie.get('areaCode')}/${params.id}`)
  }
}

// 获取游戏房间
const getRoomInfo = {
  p: [`get,/game/room/*/*`],
  r: params => {
    axios.defaults.headers.permission = `get,/game/room/*/*`
    return axios.get(`${preUrl}/game/room/${Cookie.get('areaCode')}`, {
      params
    })
  }
}

// 搜索游戏房间
const searchGameRoom = {
  p: [`get,/game/room/*/roomInfo/*`],
  r: params => {
    axios.defaults.headers.permission = `get,/game/room/*/roomInfo/*`
    return axios.get(`${preUrl}/game/room/${Cookie.get('areaCode')}/roomInfo/${params.roomNo}`)
  }
}

// 获取游戏房间详情
const getRoomDetails = {
  p: [`get,/game/room/*/*`],
  r: params => {
    axios.defaults.headers.permission = `get,/game/room/*/*`
    return axios.get(`${preUrl}/game/room/${Cookie.get('areaCode')}/${params.id}`)
  }
}

// 解散游戏房间
const dismissRoom = {
  p: [`put,/game/room/*/delete/**`],
  r: params => {
    axios.defaults.headers.permission = `put,/game/room/*/delete/**`
    return axios.put(`${preUrl}/game/room/${Cookie.get('areaCode')}/delete`, {
      params
    })
  }
}

// 移除房间成员
const removePlayer = {
  p: [`put,/game/room/*/delete/**`],
  r: params => {
    axios.defaults.headers.permission = `put,/game/room/*/delete/**`
    return axios.put(`${preUrl}/game/room/${Cookie.get('areaCode')}/delete`, {
      params
    })
  }
}

export {
  getAnnounces,
  addAnnounce,
  toggleAnnounce,
  editAnnounce,
  deleteAnnounce,
  getRoomInfo,
  searchGameRoom,
  getRoomDetails,
  dismissRoom,
  removePlayer,
}